package com.ruoyu.cloud.ai.chat.respository;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class InMemoryChatHistoryRespository implements ChatHistoryRespository {

    private final Map<String, List<String>> map = new HashMap<>();

    @Override
    public void save(String type, String chatId) {
        List<String> chatIds = map.computeIfAbsent(type, k -> new ArrayList<>());
        if (chatIds.contains(chatId)) {
            return;
        }
        chatIds.add(chatId);
    }

    @Override
    public List<String> getChatIds(String type) {
        /*List<String> chatIds = map.get(type);
        return chatIds == null ? List.of() : chatIds;*/
        return map.getOrDefault(type, List.of());
    }
}
